#include <stdio.h>
#include <stdlib.h>

#include "msg_queue.h"
#include "decrypt.h"


void init_MsgQueue(MsgQueue* queue) {
    queue->data = (WrappedData*) malloc(sizeof(WrappedData) * MAX_QUEUE_SIZE);
    queue->head = 0;
    queue->tail = 0;
    queue->size = 0;
}
int empty_MsgQueue(const MsgQueue* queue) {
    return queue->size == 0;
}
int full_MsgQueue(const MsgQueue* queue) {
    return queue->size == MAX_QUEUE_SIZE;
}
void push_MsgQueue(MsgQueue* queue, const WrappedData* data) {
    if (full_MsgQueue(queue)) {
        printf("Queue is full\n");
        return;
    }
    queue->data[queue->tail] = *data;
    queue->tail = (queue->tail + 1) % MAX_QUEUE_SIZE;
    queue->size++;
}
WrappedData* head_MsgQueue(const MsgQueue* queue) {
    return &queue->data[queue->head];
}
void pop_MsgQueue(MsgQueue* queue) {
    if (empty_MsgQueue(queue)) {
        printf("Queue is empty\n");
        return;
    }
    queue->head = (queue->head + 1) % MAX_QUEUE_SIZE;
    queue->size--;
}
void destroy_MsgQueue(MsgQueue* queue) {
    free(queue->data);
}
